package com.water.wfo.user.ability.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.water.wfo.sys.pojo.entity.RoleEntity;
import com.water.wfo.sys.pojo.entity.UserEntity;
import com.water.wfo.sys.pojo.request.RoleRequest;
import com.water.wfo.sys.pojo.response.RoleResponse;
import com.water.wfo.sys.pojo.response.UserResponse;
import com.water.wfo.user.ability.RoleAbility;
import com.water.wfo.user.mapper.RoleMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 角色表 服务实现类
 * </p>
 *
 * @author water&7
 * @since 2024-07-24
 */
@Slf4j
@Component
public class RoleAbilityImpl implements RoleAbility {
    @Autowired
    private RoleMapper roleMapper;

    @Override
    public int insert(RoleEntity entity) {
        return roleMapper.insert(entity);
    }

    @Override
    public int update(RoleEntity entity) {
        return roleMapper.update(entity);
    }

    @Override
    public List<RoleEntity> queryAllRoleEntity() {
        return roleMapper.queryAllRoleEntity();
    }

    @Override
    public List<RoleEntity> queryRoleEntityBy(RoleEntity entity) {
        return roleMapper.queryRoleEntityBy(entity);
    }

    @Override
    public RoleResponse queryRoleListInfo(RoleRequest request) {
        List<RoleEntity> roleEntities = null;
        try {
            PageHelper.startPage(request.getPageNum(),request.getPageSize());
            roleEntities = roleMapper.queryRoleListInfo(request);
        } catch (Exception e) {
            log.error(e.getMessage());
        } finally {
            PageHelper.clearPage();
        }
        //得到分页的结果对象
        PageInfo<RoleEntity> personPageInfo = new PageInfo<>(roleEntities);
        //得到分页中条目对象
        List<RoleEntity> pageList = personPageInfo.getList();
        RoleResponse response = new RoleResponse();
        response.setRoles(pageList);
        response.setTotal(personPageInfo.getTotal());
        return response;
    }
}
